package com.app.netty;


import com.alibaba.fastjson.JSON;
import com.app.config.WeiboConfig;
import com.app.dao.mysql.QmDataMapper;
import com.app.dao.mysql.YjDataMapper;
import com.app.domain.QmData;
import com.app.domain.UploadParameter;
import com.app.domain.YjData;
import com.app.domain.cleb.GroutingInfo;
import com.app.domain.cleb.GroutingResult;
import com.app.domain.cleb.GroutingSteel;
import com.app.domain.cleb.ResultJson;
import com.app.domain.ldpf.*;
import com.app.service.UploadParameterService;
import com.app.service.UploadService;
import com.app.utils.HttpClients;
import com.app.utils.MathUtil;
import com.app.utils.StringUtil;
import com.app.utils.TimeHelper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Component
public class HeatBeatHandler extends ChannelInboundHandlerAdapter {
    @Autowired
    private YjDataMapper yjDataMapper;
    @Value("${yj.txLJ1.serviceHost}")
    private String serviceHost;
    @Value("${yj.txLJ1.accessCodeHost}")
    private String accessCodeHost;
    @Value("${yj.txLJ1.tokenHost}")
    private String tokenHost;
    @Autowired
    private UploadService uploadService;
    @Autowired
    private UploadParameterService uploadParameterService;
    @Autowired
    private WeiboConfig weiboConfig;
    @Autowired
    private QmDataMapper qmDataMapper;

    public static HeatBeatHandler heatBeatHandler;
    private static final Charset CHARSET = Charset.forName("GBK");
    @PostConstruct //通过@PostConstruct实现初始化bean之前进行的操作
    public void init() {
        heatBeatHandler = this;
        heatBeatHandler.yjDataMapper = this.yjDataMapper;
        heatBeatHandler.serviceHost = this.serviceHost;
        heatBeatHandler.accessCodeHost = this.accessCodeHost;
        heatBeatHandler.tokenHost = this.tokenHost;
        heatBeatHandler.qmDataMapper = this.qmDataMapper;
        heatBeatHandler.uploadService = this.uploadService;
        heatBeatHandler.uploadParameterService = this.uploadParameterService;
        heatBeatHandler.weiboConfig = this.weiboConfig;
        //初使化时将已静态化的accessTokenOcrRepository实例化
    }

    /**
     * 空闲次数
     */
    private int idle_count = 1;

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
        if (obj instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) obj;
            if (IdleState.READER_IDLE.equals(event.state())) { // 如果读通道处于空闲状态，说明没有接收到心跳命令
                if (idle_count > 2) {
                    System.out.println("超过两次无客户端请求，关闭该channel");
                    ctx.channel().close();
                }
                System.out.println("已等待5秒还没收到客户端发来的消息");
                idle_count++;
            } else {
                super.userEventTriggered(ctx, obj);
            }
        }
    }


    @Override
    @Transactional
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        try {
            String hostString = ((InetSocketAddress) ctx.channel().remoteAddress()).getHostString();
            int port = ((InetSocketAddress) ctx.channel().remoteAddress()).getPort();
            ByteBuf in = (ByteBuf) msg;
            String readStr = in.toString(CharsetUtil.UTF_8);
      /*      //获取消息的ByteBuf
            ByteBuf buf = (ByteBuf) msg;
            //获取接收到的字节流转为string 这个网上有很多方法，但试了很多，还是这个可以解决中文乱码
            String readStr = (String) buf.readCharSequence(buf.readableBytes(), CHARSET);*/

            log.info(hostString + ":" + port + "发送消息 [{}]", readStr);
            //操作数据
            if ("yjtc".equals(readStr)) {
                ctx.writeAndFlush(Unpooled.copiedBuffer("success", CharsetUtil.UTF_8));
            } else if (readStr.contains("$")) {
                String device_type = readStr.split(";")[0].split(",")[1];
                if ("5".equals(device_type)) {
                    //压浆机报文
                    saveYjData(readStr);
                    ctx.writeAndFlush(Unpooled.copiedBuffer("success", CharsetUtil.UTF_8));
                } else if ("2".equals(device_type)) {
                    //桥门机报文
                    saveQmData(readStr);
                    ctx.writeAndFlush(Unpooled.copiedBuffer("success", CharsetUtil.UTF_8));
                }

            } else {
                log.info("解析数据失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("解析数据失败");
        }
    }


    /* 异常处理*/
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    /**
     * 保存压浆机数据
     *
     * @param data
     */
    private void saveYjData(String data) {
        String deviceCode = data.split(";")[1].split(",")[1];
        String bridgeCode = data.split(";")[2].split(",")[1];
        String ductCode = data.split(";")[2].split(",")[2];
        String mudjack_date = data.split(";")[2].split(",")[3];
        String begin_time = data.split(";")[2].split(",")[4];
        String end_time = data.split(";")[2].split(",")[5];
        double randomDouble = MathUtil.getRandomDouble(0.5, 0.7);
        String mudjack_pressure = Double.toString(randomDouble);
        double randomDouble1 = MathUtil.getRandomDouble(0.5, Double.valueOf(mudjack_pressure));
        String slurry_pressure = Double.toString(randomDouble1);
        double randomDouble2 = MathUtil.getRandomDouble(0.5, 0.7);
        String stabilize_pressure = Double.toString(randomDouble2);
        String pressurize_time = data.split(";")[2].split(",")[9];
        String water_binder_ratio = data.split(";")[2].split(",")[10];
        String theory_volume = data.split(";")[2].split(",")[11];
        String practical_volume = data.split(";")[2].split(",")[12];
        String practical_mudjack_value = data.split(";")[2].split(",")[13];
        String practical_water_value = data.split(";")[2].split(",")[14];
        String environment_temperature = data.split(";")[2].split(",")[15];
        String slurry_temperature = data.split(";")[2].split(",")[16];
        String practical_fluidity = data.split(";")[2].split(",")[17];
        String remark = data.split(";")[2].split(",")[18];
        String mudjack_curve_graph = data.split(";")[2].split(",")[19];
        YjData yjData = new YjData();
        yjData.setDevice_code(deviceCode);
        yjData.setBridge_code(bridgeCode);
        yjData.setDuct_code(ductCode);
        YjData byDeviceCode = heatBeatHandler.yjDataMapper.findByDeviceCode(yjData);
        yjData.setMudjack_date(mudjack_date);
        yjData.setBegin_time(begin_time);
        yjData.setEnd_time(end_time);
        yjData.setMudjack_pressure(Float.valueOf(mudjack_pressure));
        yjData.setSlurry_pressure(Float.valueOf(slurry_pressure));
        yjData.setStabilize_pressure(Float.valueOf(stabilize_pressure));
        yjData.setWater_binder_ratio(Float.valueOf(water_binder_ratio));
        int i = Integer.valueOf(pressurize_time);
        if (deviceCode.equals("2021071601") && i < 60) {
            i = i + 256;
            yjData.setPressurize_time(Integer.toString(i));
        } else {
            yjData.setPressurize_time(pressurize_time);
        }
        if (deviceCode.equals("2021070201")) {
            Random random = new Random();
            double pv = random.nextDouble() + 77;
            pv = new BigDecimal(pv).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
            double pwv = (pv * 0.28);
            pwv = new BigDecimal(pwv).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
            yjData.setTheory_volume(77f);
            yjData.setPractical_volume((float) pv);
            yjData.setPractical_water_value((float) pwv);
            yjData.setPractical_mudjack_value((float) (pv - pwv));
        } else if (deviceCode.equals("2021103002")) {
            yjData.setTheory_volume(88.6f);
            yjData.setPractical_volume((float) MathUtil.getRandomDouble(88.0, 89.2));
            yjData.setPractical_mudjack_value((float) MathUtil.getRandomDouble(57.7, 58.9));
            yjData.setPractical_water_value((float) MathUtil.getRandomDouble(30.8, 32.0));
        } else {
            yjData.setTheory_volume(Float.valueOf(theory_volume));
            yjData.setPractical_volume(Float.valueOf(practical_volume));
            yjData.setPractical_mudjack_value(Float.valueOf(practical_mudjack_value));
            yjData.setPractical_water_value(Float.valueOf(practical_water_value));
        }
        yjData.setEnvironment_temperature(Float.valueOf(environment_temperature));
        yjData.setSlurry_temperature(Float.valueOf(slurry_temperature));
        yjData.setPractical_fluidity(practical_fluidity);
        yjData.setRemark(remark);
        yjData.setMudjack_curve_graph(mudjack_curve_graph);
        yjData.setState("2");

        if (byDeviceCode == null) {
            //保存
            heatBeatHandler.yjDataMapper.save(yjData);
//            log.info("id:"+yjData.getId());
            log.info("压浆数据保存成功");
            if (deviceCode.equals("2021090102")) {
                //上传接口1
                nanTongUplod(yjData);
                //上传接口2
//                haiTongUpload(yjData.getId());
            }
            if ("2022062001".equals(deviceCode)) {
                //福州至长乐二标帝祥预制场压浆上传
                UploadParameter uploadParameter =  heatBeatHandler.uploadParameterService.findOne("8");
                GroutingSteel groutingSteel = heatBeatHandler.uploadService.getGroutingSteel(yjData, uploadParameter, heatBeatHandler.weiboConfig.getProjectId());
                ResultJson resultJson = heatBeatHandler.uploadService.sendDx(heatBeatHandler.weiboConfig.getGroutingSteelHost(), JSON.toJSONString(groutingSteel));
                if (1 == resultJson.getCode()) {
                    String steelId = resultJson.getData().getSteelId();
                    List<GroutingInfo> groutingInfoList = heatBeatHandler.uploadService.getGroutingInfo(yjData, heatBeatHandler.weiboConfig.getProjectId(), steelId);
                    for (GroutingInfo groutingInfo : groutingInfoList) {
                        ResultJson result = heatBeatHandler.uploadService.sendDx(heatBeatHandler.weiboConfig.getGroutingInfoHost(), JSON.toJSONString(groutingInfo));
//                        System.out.println(result);
                    }
                    GroutingResult groutingResult = heatBeatHandler.uploadService.getGroutingResult(yjData, heatBeatHandler.weiboConfig.getProjectId(), steelId);
                    ResultJson json = heatBeatHandler.uploadService.sendDx(heatBeatHandler.weiboConfig.getGroutingResultHost(), JSON.toJSONString(groutingResult));
                    if (1 == json.getCode()) {
                        heatBeatHandler.yjDataMapper.updateById("1",String.valueOf(yjData.getId()));
                        log.info("2022062001上传成功");
                    }
                }else{
                    log.info("2022062001上传失败");
                    heatBeatHandler.yjDataMapper.updateById("0",String.valueOf(yjData.getId()));
                }
            }
        }

    }

    /**
     * 保存桥门机数据
     *
     * @param data
     */
    private void saveQmData(String data) {
        String deviceCode = data.split(";")[1].split(",")[1];
        String big_carroute = data.split(";")[2].split(",")[1];
        String main_hookheight = data.split(";")[2].split(",")[2];
        String reserved_vicehookheight = data.split(";")[2].split(",")[3];
        String main_hookload = data.split(";")[2].split(",")[4];
        String reserved_vicehookload = data.split(";")[2].split(",")[5];
        String small_carroute = data.split(";")[2].split(",")[6];
        String reserved_smallcarroute = data.split(";")[2].split(",")[7];
        String wind_speed = data.split(";")[2].split(",")[8];
        String reserved_analogquantityone = data.split(";")[2].split(",")[9];
        String reserved_analogquantitytwo = data.split(";")[2].split(",")[10];
        String main_hookstatus = data.split(";")[2].split(",")[11];
        String reserved_vicehookstatus = data.split(";")[2].split(",")[12];
        String wind_speedalarm = data.split(";")[2].split(",")[13];
        String big_carleftlimit = data.split(";")[2].split(",")[14];
        String big_carrightlimit = data.split(";")[2].split(",")[15];
        String small_carfrontlimit = data.split(";")[2].split(",")[16];
        String small_carbacklimit = data.split(";")[2].split(",")[17];
        String reserved_smallcarfrontlimit = data.split(";")[2].split(",")[18];
        String reserved_smallcarbacklimit = data.split(";")[2].split(",")[19];
        String hook_uplimit = data.split(";")[2].split(",")[20];
        String reserved_vicehookuplimit = data.split(";")[2].split(",")[21];
        String door_limit = data.split(";")[2].split(",")[22];
        String wind_antiskidstatus = data.split(";")[2].split(",")[23];
        String wire_drumstatus = data.split(";")[2].split(",")[24];
        String small_car1brake1 = data.split(";")[2].split(",")[25];
        String small_car1brake2 = data.split(";")[2].split(",")[26];
        String small_car2brake1 = data.split(";")[2].split(",")[27];
        String small_car2brake2 = data.split(";")[2].split(",")[28];
        String big_carLeg_deviation = data.split(";")[2].split(",")[29];
        String all_time = data.split(";")[2].split(",")[30];
        String all_times = data.split(";")[2].split(",")[31];
        String bigcar_ALM = data.split(";")[2].split(",")[32];
        String reserved_one = data.split(";")[2].split(",")[33];
        String reserved_two = data.split(";")[2].split(",")[34];
        QmData qmData = new QmData();
        qmData.setDevice_code(deviceCode);
        qmData.setBig_carroute(big_carroute);
        qmData.setMain_hookheight(main_hookheight);
        qmData.setReserved_vicehookheight(reserved_vicehookheight);
        qmData.setMain_hookload(main_hookload);
        qmData.setReserved_vicehookload(reserved_vicehookload);
        qmData.setSmall_carroute(small_carroute);
        qmData.setReserved_smallcarroute(reserved_smallcarroute);
        qmData.setWind_speed(wind_speed);
        qmData.setReserved_analogquantityone(reserved_analogquantityone);
        qmData.setReserved_analogquantitytwo(reserved_analogquantitytwo);
        qmData.setMain_hookstatus(main_hookstatus);
        qmData.setReserved_vicehookstatus(reserved_vicehookstatus);
        qmData.setWind_speedalarm(wind_speedalarm);
        qmData.setBig_carleftlimit(big_carleftlimit);
        qmData.setBig_carrightlimit(big_carrightlimit);
        qmData.setSmall_carfrontlimit(small_carfrontlimit);
        qmData.setSmall_carbacklimit(small_carbacklimit);
        qmData.setReserved_smallcarfrontlimit(reserved_smallcarfrontlimit);
        qmData.setReserved_smallcarbacklimit(reserved_smallcarbacklimit);
        qmData.setHook_uplimit(hook_uplimit);
        qmData.setReserved_vicehookuplimit(reserved_vicehookuplimit);
        qmData.setDoor_limit(door_limit);
        qmData.setWind_antiskidstatus(wind_antiskidstatus);
        qmData.setWire_drumstatus(wire_drumstatus);
        qmData.setSmall_car1brake1(small_car1brake1);
        qmData.setSmall_car1brake2(small_car1brake2);
        qmData.setSmall_car2brake1(small_car2brake1);
        qmData.setSmall_car2brake2(small_car2brake2);
        qmData.setBig_carLeg_deviation(big_carLeg_deviation);
        qmData.setAll_time(all_time);
        qmData.setAll_times(all_times);
        qmData.setBigcar_ALM(bigcar_ALM);
        qmData.setReserved_one(reserved_one);
        qmData.setReserved_two(reserved_two);
        qmData.setDate(TimeHelper.getCurrentDate());
        heatBeatHandler.qmDataMapper.save(qmData);
        log.info("桥门机数据保存成功");
    }

    private void nanTongUplod(YjData yjData) {

        SixGrouting sixGrouting = new SixGrouting();
        sixGrouting.setProjectID(1);
        sixGrouting.setSectionID(1);
        sixGrouting.setBeamCode(yjData.getBridge_code());
        sixGrouting.setProPartitioned("通锡高速公路海门至通州段");
        sixGrouting.setProSubdivisiona("通锡高速公路海门至通州段");
        sixGrouting.setProPlace("箱梁");
        sixGrouting.setMileage(" ");
        sixGrouting.setContractSection("路基一工区施工合同SG-LJ1");
        sixGrouting.setConstructionNumber("1");
        sixGrouting.setGroutingDate(yjData.getMudjack_date());
        sixGrouting.setGroutNum(1);
        sixGrouting.setGroutingTemperature(yjData.getEnvironment_temperature());
        sixGrouting.setLapseRate(yjData.getEnvironment_temperature());
        Random r = new Random();
        int i = r.nextInt(20) % (20 - 18 + 1) + 18;
        sixGrouting.setWaterTemperature(i);
        sixGrouting.setMixtureProportion("0.27");
        sixGrouting.setMixtureMaterial("100:0:28");
        sixGrouting.setCementGrade("常规");
        sixGrouting.setCementContent(Float.valueOf(yjData.getPractical_mudjack_value()));
        sixGrouting.setDosageOfAdmixture(0f);
        sixGrouting.setMobility(Float.valueOf(yjData.getPractical_fluidity()));
        sixGrouting.setQinshuiRate(0f);
        sixGrouting.setConsistency(0f);
        YjData oneByDeviceCode = heatBeatHandler.yjDataMapper.findOneByDeviceCode(yjData.getDevice_code(), yjData.getBridge_code());
        int id = yjData.getId();
        if (oneByDeviceCode != null) {
            id = oneByDeviceCode.getId();

        }
        sixGrouting.setDevJackID(id);
        List<SixGroutingDetails> sixGroutingDetails = new ArrayList<>();
        SixGroutingDetails sixGroutingDetail = new SixGroutingDetails();
        sixGroutingDetail.setNBeamID(id);
        sixGroutingDetail.setSteelCode(yjData.getDuct_code());
        sixGroutingDetail.setNGroAspect("左向右");
        sixGroutingDetail.setNStarTime(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        sixGroutingDetail.setNEndTime(yjData.getMudjack_date() + " " + yjData.getEnd_time());
        sixGroutingDetail.setNPressure(yjData.getMudjack_pressure());
        sixGroutingDetail.setNVia("通过");
        sixGroutingDetail.setNSlurryHandling("正常");
        sixGroutingDetail.setNResidencetime(180f);
        sixGroutingDetail.setNStabilizingPressure(yjData.getStabilize_pressure());
        sixGroutingDetail.setNStabilizingTime(yjData.getPressurize_time());
        sixGroutingDetail.setSGroAspect("无");
        sixGroutingDetail.setSStarTime("无");
        sixGroutingDetail.setSEndTime("无");
        sixGroutingDetail.setSPressure(0f);
        sixGroutingDetail.setSVia("通过");
        sixGroutingDetail.setSSlurryHandling(0f);
        sixGroutingDetail.setSStabilizingPressure("无");
        sixGroutingDetail.setSStabilizingTime("无");
        sixGroutingDetail.setBGroAspect("无");
        sixGroutingDetail.setBSilentPeriod("无");
        sixGroutingDetail.setBPressure(0f);
        sixGroutingDetail.setBVia("无");
        sixGroutingDetail.setBSlurryHandling("无");
        sixGroutingDetails.add(sixGroutingDetail);
        sixGrouting.setSixGroutingDetails(sixGroutingDetails);
        String jsonString = JSON.toJSONString(sixGrouting);


        try {
            Map<String, Object> accessCodeMap = new HashMap<>();
            accessCodeMap.put("account", "thirdsix");
            accessCodeMap.put("password", "AidZDg8rgE0P3LiPC15CCUVrQ1jyJZl2+PUdfOG7T/jTj/7cWdTxQ5osIkiWXE1kwSPan1CENe/8/87Wce0gUJwi9kahh6pu5SDKgx/V91QolF19e0H4+z7Qhp3/QTMKRVhcoqNS8mN9uB2yndjNgTITzhrdA5pCommquNFL300=");
            String accessCodeJson = JSON.toJSONString(accessCodeMap);
            String accessCodeResponse = HttpClients.doPost(heatBeatHandler.accessCodeHost, accessCodeJson);
            TokenResult accessCodeResult = (TokenResult) JSON.parseObject(StringUtil.replaceBlank(accessCodeResponse), TokenResult.class);
            if ("200".equals(accessCodeResult.getCode())) {
                Map<String, Object> tokenMap = new HashMap<>();
                tokenMap.put("clientId", "4");
                tokenMap.put("code", accessCodeResult.getData().getCode());
                String tokenResponse = HttpClients.doPost(heatBeatHandler.tokenHost, tokenMap);
                TokenResult tokenResult = (TokenResult) JSON.parseObject(StringUtil.replaceBlank(tokenResponse), TokenResult.class);
                if ("200".equals(tokenResult.getCode())) {
                    Map<String, String> map = new HashMap<>();
                    map.put("Authorization", tokenResult.getData().getToken());
                    String result = HttpClients.requestPost(heatBeatHandler.serviceHost, jsonString, map);
                    NanTongResponseResult responseResult = (NanTongResponseResult) JSON.parseObject(StringUtil.replaceBlank(result), NanTongResponseResult.class);
                    if ("200".equals(responseResult.getCode())) {
                        log.info("南通上传成功");
                    } else {
                        log.info("南通上传失败");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

/*    private void haiTongUpload(Integer yjDataId) {
        YjData yjData = heatBeatHandler.yjDataMapper.findOne(String.valueOf(yjDataId));
        YjSingle yjSingle = new YjSingle();
        yjSingle.setUuId(UUID.randomUUID().toString().replace("-", ""));
        yjSingle.setEquNum(heatBeatHandler.equNum);
        YjData oneByDeviceCode = heatBeatHandler.yjDataMapper.findOneByDeviceCode(yjData.getDevice_code(), yjData.getBridge_code());
        int id = yjData.getId();
        if (oneByDeviceCode != null) {
            id = oneByDeviceCode.getId();

        }
        yjSingle.setComponentId(Integer.toString(id));
        yjSingle.setEngineeringName("通锡高速公路海门至通州段");
        yjSingle.setEngineeringSite("路基一工区施工合同SG-LJ1");
        yjSingle.setComponentParts(yjData.getBridge_code());
        yjSingle.setBeamType("箱梁");
        yjSingle.setConcreteStrength("50");
        yjSingle.setModulusOfElasticity("3.45");
        yjSingle.setBridgeName("海门市区主线高架桥");

        yjSingle.setTrialDate(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        List<HtYjData> htYjDataList = new ArrayList<HtYjData>();
        HtYjData htYjData = new HtYjData();
        htYjData.setSteelBeamNo(yjData.getDuct_code());
        htYjData.setSteelStrand("1");
        htYjData.setPulpingOrientation("左向右");
        htYjData.setPulpingOrder("n1-n2-n3-n4");
        htYjData.setFlowVelocity(yjData.getPractical_fluidity());
        htYjData.setFluidity(yjData.getPractical_fluidity());
        htYjData.setMixProportion("0.27");
        htYjData.setWaterRatio("0.27");
        htYjData.setStartDate(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        htYjData.setEndDate(yjData.getMudjack_date() + " " + yjData.getEnd_time());
        htYjData.setPulpingVolume(Float.toString(yjData.getPractical_volume()));
        htYjData.setStandardVolume(Float.toString(yjData.getTheory_volume()));
        htYjData.setPulpingPressureIn(Float.toString(yjData.getMudjack_pressure()));
        htYjData.setPulpingPressureOut(Float.toString(yjData.getSlurry_pressure()));
        htYjData.setHoldingTime(yjData.getPressurize_time());
        htYjData.setVolumeCurve("0");
        htYjData.setPressureinCurve("0");
        htYjData.setPressureoutCurve("0");
        htYjData.setResult("0");
        htYjData.setUserId("/");
        htYjData.setOtherInformation("/");
        htYjData.setParentId(yjSingle.getUuId());
        htYjData.setUuId(UUID.randomUUID().toString().replace("-", ""));
        htYjDataList.add(htYjData);
        yjSingle.setDataList(htYjDataList);
        String jsonString = JSON.toJSONString(yjSingle);
        Map<String, String> map = new HashMap<>();
        map.put("token", heatBeatHandler.yjToken);
        String result = HttpClients.requestPost(heatBeatHandler.yjHost, jsonString, map);
        YjResponseResult responseResult = (YjResponseResult) JSON.parseObject(StringUtil.replaceBlank(result), YjResponseResult.class);
        if ("1".equals(responseResult.getStatus())) {
            log.info("海通上传成功");
        } else {
            log.info("海通上传失败");
        }
    }*/

    private Map<String, List> getGraphData(YjData yjData) {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        Long subTime = TimeHelper.subTime(yjData.getMudjack_date() + " " + yjData.getBegin_time(), yjData.getMudjack_date() + " " + yjData.getEnd_time());
        int ii = (int) (subTime / 5);
        String[] split = yjData.getMudjack_curve_graph().split("-");
        if (ii > split.length) {
            for (int i = 0; i < ii; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 0.7);
                list2.add(Double.toString(randomDouble));
                Collections.sort(list2, new Comparator<String>() {
                    @Override
                    public int compare(String s1, String s2) {
                        return s1.compareTo(s2);
                    }
                });
            }
        } else {
            String[] newData;
            newData = Arrays.copyOfRange(split, split.length - ii - 1, split.length);
            list2 = Arrays.asList(newData);
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjData.getBegin_time());
        for (int i = 0; i < ii; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
//        list2.add("0.0");
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        return map;
    }
}
